/ leetcodesolve / 50. Pow(x, n).py
swadhinbiswas update on LeetcodeSolve · 1/30/2025
e22678e
14 lines · 310 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution:
   
    def myPow(self, x: float, n: int) -> float:
        def helper(x,n):
            if n==0:return 1
            if x==0:return 0
            res=helper(x*x,n//2)
            return x*res if n%2!=0 else res
        res=helper(x,abs(n))
        return res if n>=0 else 1/res